// 设置高考日期（2026年6月7日）
const examDate = new Date('2026-06-07T09:00:00');

// 获取DOM元素
const daysElement = document.getElementById('days');
const hoursElement = document.getElementById('hours');
const minutesElement = document.getElementById('minutes');
const secondsElement = document.getElementById('seconds');
const millisecondsElement = document.getElementById('milliseconds');
const currentDatetimeElement = document.getElementById('current-datetime');

// 更新倒计时
function updateCountdown() {
    const now = new Date();

    // 更新当前日期和时间
    const options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' };
    currentDatetimeElement.textContent = "今天日期：" + now.toLocaleDateString('zh-CN', options);

    const diff = examDate - now;

    // 如果考试已经开始
    if (diff <= 0) {
        daysElement.textContent = '00';
        hoursElement.textContent = '00';
        minutesElement.textContent = '00';
        secondsElement.textContent = '00';
        millisecondsElement.textContent = '000';
        return;
    }

    // 计算剩余时间
    const days = Math.floor(diff / (1000 * 60 * 60 * 24));
    const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
    const seconds = Math.floor((diff % (1000 * 60)) / 1000);
    const milliseconds = Math.floor(diff % 1000);

    // 更新显示
    daysElement.textContent = String(days).padStart(2, '0');
    hoursElement.textContent = String(hours).padStart(2, '0');
    minutesElement.textContent = String(minutes).padStart(2, '0');
    secondsElement.textContent = String(seconds).padStart(2, '0');
    millisecondsElement.textContent = String(milliseconds).padStart(3, '0');

    // 添加数字变化动画
    if (milliseconds < 100 && milliseconds > 0) {
        addAnimationClass(secondsElement);
    }
    if (seconds === 0) {
        addAnimationClass(minutesElement);
    }
    if (minutes === 0 && seconds === 0) {
        addAnimationClass(hoursElement);
    }
    if (hours === 0 && minutes === 0 && seconds === 0) {
        addAnimationClass(daysElement);
    }
}

// 添加动画类
function addAnimationClass(element) {
    element.classList.add('animate');
    setTimeout(() => {
        element.classList.remove('animate');
    }, 1000);
}

// 每10毫秒更新一次
setInterval(updateCountdown, 10);

// 立即执行一次，避免初始延迟
updateCountdown(); 